﻿using System;
using System.Runtime.CompilerServices;

namespace LINQPadLogParser
{
  public sealed class SimpleUriWrapper : IFormattable
  {
    private readonly string _value;
    private Uri _uri;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public SimpleUriWrapper(string value)
    {
      _value = value;
    }

    private Uri Uri
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _uri ?? (_uri = new Uri(_value, UriKind.RelativeOrAbsolute)); }
    }

    public string AbsolutePath
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.AbsolutePath; }
    }

    public string AbsoluteUri
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.AbsoluteUri; }
    }

    public string LocalPath
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.LocalPath; }
    }

    public string Authority
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Authority; }
    }

    public UriHostNameType HostNameType
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.HostNameType; }
    }

    public bool IsDefaultPort
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.IsDefaultPort; }
    }

    public bool IsFile
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.IsFile; }
    }

    public bool IsLoopback
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.IsLoopback; }
    }

    public string PathAndQuery
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.PathAndQuery; }
    }

    public string[] Segments
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Segments; }
    }

    public bool IsUnc
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.IsUnc; }
    }

    public string Host
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Host; }
    }

    public int Port
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Port; }
    }

    public string Query
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Query; }
    }

    public string Fragment
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Fragment; }
    }

    public string Scheme
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.Scheme; }
    }

    public string OriginalString
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _value; }
    }

    public string DnsSafeHost
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.DnsSafeHost; }
    }

    public bool IsAbsoluteUri
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.IsAbsoluteUri; }
    }

    public bool UserEscaped
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.UserEscaped; }
    }

    public string UserInfo
    {
      [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Uri.UserInfo; }
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string ToString(string format, IFormatProvider formatProvider)
    {
      return ToString();
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public override string ToString()
    {
      return _value ?? string.Empty;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string GetLeftPart(UriPartial part)
    {
      return Uri.GetLeftPart(part);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public Uri MakeRelativeUri(Uri uri)
    {
      return Uri.MakeRelativeUri(uri);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string MakeRelative(Uri toUri)
    {
// ReSharper disable once CSharpWarnings::CS0618
      return Uri.MakeRelative(toUri);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public string GetComponents(UriComponents components, UriFormat format)
    {
      return Uri.GetComponents(components, format);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public bool IsWellFormedOriginalString()
    {
      return Uri.IsWellFormedOriginalString();
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public bool IsBaseOf(Uri uri)
    {
      return Uri.IsBaseOf(uri);
    }
  }
}